import { createApp, Directive } from 'vue'
import './style.css'
import App from './App.vue'
import { createPinia } from 'pinia'
import piniaPersist from 'pinia-plugin-persist'
import 'babel-polyfill'
// import 'default-passive-events'
import { useMain } from "@/store/index";
import { get_token } from "@/utils/token";
import router from "./routes/index";

import { capturePassive } from "@/utils/polyfill";// 去除touch事件谷歌提示

capturePassive();


const app = createApp(App)
// 创建 pinia 实例
const pinia = createPinia()

app.use(pinia);
app.use(router);
pinia.use(piniaPersist);
app.mount('#app');


const useMainStore = useMain();

//路由守卫
router.beforeEach((to, from, next) => {
    // let token = useMainStore.authToken ? useMainStore.authToken : '';
    // //如果是登录页,获取忘记密码页面,直接跳转
    // if (to.path == '/login' || to.path == '/forgetPassword') {
    //     next();
    // } else {
    //     //有token直接跳转,无token则跳转回登录页
    //     if (token) {
    //         next();
    //     } else {
    //         next('/login');
    //     }
    // }
    next();
})


  //每20分钟重新获取一次token
  setInterval(() => {
    get_token();
  }, 1200000);